package online.chenlu.blog.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import online.chenlu.blog.core.Result;
import online.chenlu.blog.model.TeamExam;
import online.chenlu.blog.service.TeamExamService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Describe TeamExamController
 * @Author chenlu
 * @Version V1.0
 * @Date 2019/03/27.
 */
@Api(value = "TeamExamController", tags = "TeamExam")
@Slf4j
@RestController
@RequestMapping("//team/exam")
public class TeamExamController {
    @Resource
    private TeamExamService teamexamService;

    /**
     * 新增TeamExam
     *
     * @param teamexam
     * @return Result
     */
    @PostMapping
    @ApiOperation(value = "新增TeamExam", notes = "TeamExam")
    public Result add(@RequestBody TeamExam teamexam) {
        teamexamService.save(teamexam);
        log.debug("新增TeamExam.");
        return Result.success();
    }

    /**
     * 删除TeamExam
     *
     * @param id
     * @return Result
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除TeamExam", notes = "TeamExam")
    public Result delete(@PathVariable String id) {
        teamexamService.deleteById(id);
        log.debug("删除TeamExam.");
        return Result.success();
    }

    /**
     * 修改TeamExam
     *
     * @param teamexam
     * @return Result
     */
    @PutMapping
    @ApiOperation(value = "修改TeamExam", notes = "TeamExam")
    public Result update(@RequestBody TeamExam teamexam) {
        teamexamService.update(teamexam);
        log.debug("修改TeamExam.");
        return Result.success();
    }

    /**
     * 查询TeamExam
     *
     * @param id
     * @return Result
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询TeamExam", notes = "TeamExam")
    public Result detail(@PathVariable String id) {
        TeamExam teamexam = teamexamService.findById(id);
        log.debug("查询TeamExam.");
        return Result.success(teamexam);
    }

    /**
     * 列表TeamExam（支持分页）
     *
     * @param pageNum  页码
     * @param pageSize 条数
     * @param teamexam 查询条件
     * @return Result
     */
    @GetMapping
    @ApiOperation(value = "列表TeamExam（支持分页）", notes = "TeamExam")
    public Result list(@RequestParam(defaultValue = "0") Integer pageNum,
                       @RequestParam(defaultValue = "0") Integer pageSize,
                       TeamExam teamexam) {
        PageHelper.startPage(pageNum, pageSize);
        List<TeamExam> list = teamexamService.list(teamexam);
        PageInfo pageInfo = new PageInfo(list);
        log.debug("列表TeamExam.");
        return Result.success(pageInfo);
    }

}
